package com.airsystem.pos.bengkel.service;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.airsystem.pos.bengkel.entity.DetailOrderLayanan;
import com.airsystem.pos.bengkel.entity.DetailPesanSparepart;
import com.airsystem.pos.bengkel.entity.Karyawan;
import com.airsystem.pos.bengkel.entity.Tagihan;
import com.airsystem.pos.bengkel.util.DateUtil;
import com.airsystem.pos.bengkel.util.HibernateUtil;

/**
 * @author Budi Oktaviyan
 */
public class LaporanBulananServices {

	public List<Karyawan> print() throws Exception {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Criteria criteria = session.createCriteria(Karyawan.class);

		List result = criteria.list();
		session.close();

		return result;
	}

	public List<Tagihan> print(String periode) throws Exception {
		Session session = HibernateUtil.getSessionFactory().openSession();
		Criteria criteria = session.createCriteria(Tagihan.class);
		criteria.add(Restrictions.eq("periode", periode));

		List result = criteria.list();
		session.close();

		return result;
	}

	public List<DetailPesanSparepart> getAllSparepart(String periode) throws Exception {
		StringBuilder builder = new StringBuilder("DATE(tanggal) LIKE '%");
		builder.append(DateUtil.convertStringDisplay(periode));
		builder.append("%'");

		Session session = HibernateUtil.getSessionFactory().openSession();

		Criteria criteria = session.createCriteria(DetailPesanSparepart.class);
		Criteria subCriteria = criteria.createCriteria("pesan_sparepart");
		subCriteria.add(Restrictions.sqlRestriction(builder.toString()));

		List result = criteria.list();
		session.close();

		return result;
	}

	public List<DetailOrderLayanan> getAllJasa(String periode) throws Exception {
		StringBuilder builder = new StringBuilder("DATE(tanggal) LIKE '%");
		builder.append(DateUtil.convertStringDisplay(periode));
		builder.append("%'");

		Session session = HibernateUtil.getSessionFactory().openSession();

		Criteria criteria = session.createCriteria(DetailOrderLayanan.class);
		Criteria subCriteria = criteria.createCriteria("order_layanan");
		subCriteria.add(Restrictions.sqlRestriction(builder.toString()));

		List result = criteria.list();
		session.close();

		return result;
	}
}